﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BussinessLayer
{
    public class tblTaikhoan
    {
        DataLayer.Data odata = new DataLayer.Data();
        public DataTable SelectNguoidung()
        {
            return odata.view_text("SELECT nd.taikhoan, nd.id,hsgv.hoten, nd.trangthai FROM  nguoidung AS nd,hocsinh_giaovien AS hsgv WHERE nd.id=hsgv.id");
        }
        public void Insert(string _taikhoan, string _matkhau, int _id, bool _trangthai,int tp)
        {
            SqlParameter[] sp = new SqlParameter[5];
            sp[0] = new SqlParameter("@taikhoan", _taikhoan);
            sp[1] = new SqlParameter("@matkhau", _matkhau);
            sp[2] = new SqlParameter("@id", _id);
            sp[3] = new SqlParameter("@trangthai", _trangthai);
            sp[4] = new SqlParameter("@type", tp);
            odata.proc_TS("tblTaikhoan", sp);
        }
        public void updateMatKhau(string tk, string mk)
        {
            SqlParameter[] sp = new SqlParameter[5];
            sp[0] = new SqlParameter("@taikhoan", tk);
            sp[1] = new SqlParameter("@matkhau", mk);
            sp[2] = new SqlParameter("@id", 0);
            sp[3] = new SqlParameter("@trangthai", true);
            sp[4] = new SqlParameter("@type", 2); //type=2
            odata.proc_TS("tblTaikhoan", sp);
        }

        public void updateTrangThai(string tk, bool tt)
        {
            SqlParameter[] sp = new SqlParameter[5];
            sp[0] = new SqlParameter("@taikhoan", tk);
            sp[1] = new SqlParameter("@matkhau", "");
            sp[2] = new SqlParameter("@id", 0);
            sp[3] = new SqlParameter("@trangthai", tt);
            sp[4] = new SqlParameter("@type", 3); //type=3
            odata.proc_TS("tblTaikhoan", sp);
        }

        public DataTable SelectTaikhoan(string _tk)
        {
            return odata.view_text("SELECT * FROM nguoidung WHERE taikhoan='" + _tk + "'");
        }
        public DataTable checktaikhoan(string _tk,string _mk)
        {
            return odata.view_text("SELECT * FROM nguoidung WHERE taikhoan='" + _tk + "' and matkhau='"+_mk+"'");
        }

    }
}
